<?php
/**
 * Created by PhpStorm.
 * User: XYX
 * Date: 2017/9/5
 * Time: 9:35
 */

namespace App\Api\Transformers;


use App\Club;
use App\Clubbanner;
use App\Clubclass;
use App\Clubvideo;
use App\Mentor;
use League\Fractal\TransformerAbstract;

class ClubInfoTransformer extends TransformerAbstract
{
    protected $defaultIncludes = ['clubclasses', 'clubvideos','clubbanners','mentors'];
    public function transform(Club $item)
    {
        return
            [
                'club_id'=>$item['id'],
                'name'=>$item['name'],
                'address'=>$item['address'],
                'contact_tele'=>$item['contact_tele'],
                'opentime'=>$item['opentime'],
                'club_intro'=>$item['introl']
            ];
    }
    public function includeClubclasses(Club $item){
        if (! ($item->clubclasses)) {
            return $this->null();
        }
        return $this->collection($item->clubclasses, new ClubClassTransformer());
    }
    public function includeClubvideos(Club $item)
    {
        if (! ($item->clubvideos)) {
            return $this->null();
        }
        return $this->collection($item->clubvideos,new ClubvideoTransformer());
    }
    public function includeClubbanners(Club $item){
        if (! ($item->clubbanners)) {
            return $this->null();
        }
        return $this->collection($item->clubbanners, new ClubbannerTransformer());
    }
    public function includeMentors(Club $item)
    {
        if (! ($item->mentors)) {
            return $this->null();
        }
        return $this->collection($item->mentors,new MentorforClubTransformer());
    }

}